package com.zzyl.controller.customer;

import com.zzyl.base.ResponseResult;
import com.zzyl.controller.BaseController;
import com.zzyl.entity.Reservation;
import com.zzyl.service.CustomerReservationService;
import com.zzyl.utils.UserThreadLocal;
import com.zzyl.vo.ReservationSel;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/customer/reservation")
@Api(tags = "客户预约管理")
public class CustomerReservationController extends BaseController {

    @Autowired
    private CustomerReservationService customerReservationService;

    @GetMapping("/cancelled-count")
    @ApiOperation("查询取消预约数量")
    public ResponseResult<Integer> getCancelledReservationCount() {
        Integer count = customerReservationService.getCancelledReservationCount(UserThreadLocal.getUserId());
        return success(count);
    }

    @GetMapping("/countByTime")
    @ApiOperation("查询每个时间段剩余预约次数")
    public ResponseResult<ReservationSel> getCountByTime() {
        return success(customerReservationService.getCountByTime(UserThreadLocal.getUserId()));
    }

    @PostMapping
    @ApiOperation("新增预约")
    public ResponseResult addReservation(@RequestBody Reservation reservation) {
        customerReservationService.addReservation(reservation);
        return success();
    }

    @GetMapping("/page")
    @ApiOperation("分页查询预约")
    public ResponseResult<Reservation> queryReservationByPage(@ApiParam(value = "页码", required = true) @RequestParam Integer pageNum,
                                                              @ApiParam(value = "每页数量", required = true) @RequestParam Integer pageSize,
                                                              @ApiParam(value = "状态") @RequestParam(required = false) Integer status) {
        return success(customerReservationService.queryReservationByPage(pageNum,pageSize,status));
    }


    @PutMapping("/{id}/cancel")
    @ApiOperation("取消预约")
    public ResponseResult delReservationStatus(@PathVariable Long id){

        customerReservationService.delReservationStatus(id);
        return success();

    }

}